package com.jcl.recruit.elasticsearch.api.controller;

import com.jcl.core.common.page.PageResult;
import com.jcl.core.resp.ApiResponse;
import com.jcl.recruit.elasticsearch.core.entity.vo.SearchParamEntity;
import com.jcl.recruit.elasticsearch.core.entity.vo.SearchResumeRecord;
import com.jcl.recruit.elasticsearch.resume.model.SearchResumeBasicInfo;
import com.jcl.recruit.elasticsearch.resume.po.ResumeResultEntity;
import com.jcl.recruit.elasticsearch.resume.po.ResumeSimpleResultEntity;
import com.jcl.recruit.elasticsearch.resume.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName controller

 * @Author yyliu
 * @Date 2018/11/13 14:46
 * @Version 1.0
 **/
@RestController
@RequestMapping("/elastic/resume")
public class ResumeElasticController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping(value = "/page/list", method = RequestMethod.POST)
    public ApiResponse searchResumePage(@RequestBody SearchParamEntity entity) {

        String channel = entity.getChannel();
        String corpCode = entity.getCorpCode();
        Integer curPage = entity.getCurPage();
        Integer resumeUpdateDays = entity.getResumeUpdateDays();
        Integer comingDays = entity.getComingDays();
        List<SearchResumeRecord> recordList = entity.getResumeRecords();
        PageResult pageResult = resumeService.pageResult(recordList, channel, corpCode,
                curPage, resumeUpdateDays, comingDays);

        return ApiResponse.success(pageResult);
    }

    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public ApiResponse getResumeResultEntity(@PathVariable(name = "id") Integer id) {

        ResumeResultEntity data = resumeService.findResumeDetail(id);
        return ApiResponse.success(data);
    }

    @RequestMapping(value = "/get/simple/{id}", method = RequestMethod.GET)
    public ApiResponse findOne(@PathVariable(name = "id") Integer id) {

        ResumeSimpleResultEntity data = resumeService.findResumeSimpleDetail(id);
        return ApiResponse.success(data);
    }

    @RequestMapping(value = "/get/basic/{id}", method = RequestMethod.GET)
    public ApiResponse resumeBasicEntity(@PathVariable(name = "id") Integer id) {

        SearchResumeBasicInfo data = resumeService.getBasicInfo(id);
        return ApiResponse.success(data);
    }

    @RequestMapping(value = "/get/source/count", method = RequestMethod.GET)
    public ApiResponse getCountBySources(Boolean today) {
        List<Map<String, String>> list = resumeService.getCountBySources(today);
        return ApiResponse.success(list);
    }

}
